package com.cloud.sky.controller;

import com.cloud.sky.component.TingYuClient;
import com.cloud.sky.entity.bo.PageBO;
import com.cloud.sky.entity.bo.ResultBO;
import com.cloud.sky.entity.common.Result;
import com.cloud.sky.entity.common.ResultCode;
import com.cloud.sky.entity.dto.PriceConfigListDTO;
import com.cloud.sky.entity.vo.PriceConfigVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 大节点、小节点、路由器通用接口
 *
 * @author Tyrone
 * @date 2024/8/8 02:14
 */
@RestController
public class CommonController {

    @Autowired
    private TingYuClient tingYuClient;

    /**
     * 更新资源
     *
     * @param uuid uuid
     * @return
     */
    @RequestMapping("/resource/update/{uuid}")
    public Result updateResource(@PathVariable String uuid) {
        ResultBO resultBO = tingYuClient.updateResource(uuid);
        if (resultBO.isSuccess()) {
            return Result.success(null);
        }
        return Result.failure(resultBO.getMessage());
    }

    @RequestMapping("machine/price/list")
    public Result<PageBO<PriceConfigVO>> getPriceConfigList(PriceConfigListDTO priceConfigListDTO) {
        PageBO<PriceConfigVO> priceConfigList = tingYuClient.getPriceConfigList(priceConfigListDTO);
        if (priceConfigList == null) {
            return Result.failure(ResultCode.failure);
        }
        return Result.success(priceConfigList);
    }
}
